package com.quiz.bis.controller;

import com.quiz.bis.domain.bo.InviteCreateBo;
import com.quiz.bis.domain.model.ExamGroupInvite;
import com.quiz.bis.service.IExamGroupInviteService;
import com.quiz.common.core.domain.R;
import com.quiz.common.mybatis.core.page.PageQuery;
import com.quiz.common.mybatis.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 考试组邀请码管理
 * @author ahuan
 */
@RestController
@RequestMapping("/exam/group/invite")
@Tag(name = "考试组邀请码管理")
@RequiredArgsConstructor
public class ExamGroupInviteController {
    private final IExamGroupInviteService inviteService;

    /**
     * 生成邀请码
     * @param bo
     * @return
     */
    @PostMapping
    public R<ExamGroupInvite> createInvite(@Valid @RequestBody InviteCreateBo bo) {
        return inviteService.createInvite(bo);
    }

    /**
     * 获取邀请码列表
     * @param groupId
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo<ExamGroupInvite> getInvites(
            @RequestParam Long groupId,
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) Integer type,
            PageQuery pageQuery) {

        // 调用服务层方法，传递所有参数
        return inviteService.getInvites(groupId, keyword, type, pageQuery);
    }

    /**
     * 删除邀请码
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R<Void> deleteInvite(@PathVariable Long id) {
        return inviteService.deleteInvite(id);
    }
}


